<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sum</title>
    <script>
        /**
         * Created by zhangheng on 2017/5/24.
         */
        let mysum = 0;
        function sum() {
            let data = prompt("请输入一个整数",0);
            data = parseInt(data);
            if (isNaN(data)){
                window.alert("不是合法的输入!");
            }else{
                mysum = mysum + data;
                console.log(mysum);
            }

            if(data === 0){
                window.alert("和为"+mysum);
                mysum = 0;
            }
        }
    </script>
</head>
<body>
    <button id="input" onclick="sum()">输入</button>
</body>
</html>